<%@page import="java.util.TreeMap"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@page import="com.google.appengine.api.images.ImagesService"%>
<%@page import="com.google.appengine.api.images.ImagesServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@page import="entities.User"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="java.util.List"%>
<%
List<User> authors = (List<User>) request.getAttribute("authors");
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
ImagesService imagesService = ImagesServiceFactory.getImagesService();

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");

//Set content for seo
String nameServer = UrlHelper.getDomainServer(request);
TreeMap<String, String> params = new TreeMap<String, String>();
params.put("NAMESERVER__", nameServer);
params.put("PAGE__", Integer.toString(pages));

String title = StringHelper.replace(LanguageHelper.getString("author_list_title"), params) ;
String description = LanguageHelper.getString("author_list_description") + " " + nameServer ;
String keywords = LanguageHelper.getString("author_list_keywords");
String url = UrlHelper.getServerUrl(request) + "/authors";
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="keywords" value="<%=keywords %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=url %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

            <div id="mainContent" class="left" itemscope itemtype="http://schema.org/ItemList">
            	<div id="authorListingPage">
                	<h3 class="title"><%=LanguageHelper.getString("authors_title")%></h3>
                    <ul class="authorListing clearafter" itemscope itemtype="http://schema.org/Person">
                    	<% for (int i = 0; i < authors.size(); i++) { %>
                    	<li class="clearafter">
                    		<% 
								if (authors.get(i).getAvatar() != null && !authors.get(i).getAvatar().isEmpty())  {
									 BlobKey blobKey = new BlobKey(authors.get(i).getAvatar());
							%>
							<img alt="" src="<%=imagesService.getServingUrl(blobKey) %>=s100-c" class="left" >
							<% } else { %>							
							<img itemprop="image" src="/images/icon-author.jpg" class="left" />
							<% } %>
                            <h3 itemprop="name" class="authorName"><a href="/author/<%=authors.get(i).getId()%>"><%=authors.get(i).getName() %></a></h3>
                        </li>
                        <% } %>
                    </ul>
                    
                    <hr />
                    
                    <ul class="pagination">
	                    <%
						List<Integer> range = paginator.getRangePage();
						%>
	                    <% if (prevPage) { %>
						<li><a href="<%=paginator.getPrev()%>"><%=LanguageHelper.getString("prev")%></a></li>
						<% } %>
						<%
						if (nextPage || prevPage) {
							for (int i = 0; i < range.size(); i++) {
						%>
						<li><a class="<%=range.get(i).intValue() == pages ? "current" : "" %>" href="<%=range.get(i).intValue() == pages ? "javascript: return false;" : paginator.getPage(range.get(i).intValue())%>"> <%=range.get(i).toString() %> </a></li>
						<%  }
						} %>
						
						<% if (nextPage) { %>
						<li><a href="<%=paginator.getNext()%>"> <%=LanguageHelper.getString("next")%> </a></li>
						<% } %>
	                </ul>
                </div>
            </div>
            
            <jsp:include page="/elements/right.jsp" />
            
            <div class="clearbreak"></div>
<jsp:include page="/layouts/footer.jsp" />